/*
 * 
 * Note this Class has the following dependencies
 * commons-logging-1.1.1.jar
 * httpclient-4.0.1.jar
 * httpcore-4.0.1.jar
 */
package info.daveturner;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;



public class HttpUtils {
  
  public static String getResolvedUrl(String url) throws Exception
  {
    String result="";
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpContext localContext = new BasicHttpContext();
    httpclient.execute(httpget,localContext);
    HttpUriRequest currentReq = (HttpUriRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
    HttpHost currentHost = (HttpHost)  localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    result = currentHost.toURI() + currentReq.getURI();
    return result;
  }

}
